package club.emergency.wechat.manager.operate.consumer.controller;

import club.emergency.wechat.common.response.ResponseEntity;
import club.emergency.wechat.common.utils.JsonConvert;
import club.emergency.wechat.manager.operate.consumer.service.ManagerOperateConsumer;
import club.emergency.wechat.model.manager.Manager;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Create with IntelliJ IDEA
 * Project Name: wechat
 * Package Name: club.emergency.wechat.manager.operate.consumer.controller
 * Date: 2018/12/5
 *
 * @author: 快乐的小菌菌
 * Description:
 */
@RestController
@RequestMapping("/manager-operate")
public class ManagerOperateController {

    private ManagerOperateConsumer managerOperateConsumer;

    public ManagerOperateController(ManagerOperateConsumer managerOperateConsumer) {
        this.managerOperateConsumer = managerOperateConsumer;
    }

    @ApiOperation("新增人员")
    @PostMapping("/save")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "姓名", name = "userName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "昵称", name = "nickName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "角色名称", name = "roleName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "角色id", name = "roleId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门名称", name = "departmentName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门id", name = "departmentId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门code", name = "departmentCode", required = true, dataType = "string", paramType = "query")
    })
    public ResponseEntity save(
            @RequestParam("userName") String userName,
            @RequestParam("nickName") String nickName,
            @RequestParam("password") String password,
            @RequestParam("roleName") String roleName,
            @RequestParam("roleId") Long roleId,
            @RequestParam("departmentName") String departmentName,
            @RequestParam("departmentId") Long departmentId,
            @RequestParam("departmentCode") String departmentCode
    ) {
        Manager manager = new Manager();
        manager.setUserName(userName);
        manager.setNickName(nickName);
        manager.setPassword(password);
        manager.setRoleName(roleName);
        manager.setRoleId(roleId);
        manager.setDepartmentName(departmentName);
        manager.setDepartmentId(departmentId);
        manager.setDepartmentCode(departmentCode);
        return new JsonConvert<ResponseEntity>().jsonDecode(managerOperateConsumer.save(manager), ResponseEntity.class);
    }

    @ApiOperation("修改人员")
    @PostMapping("/modify")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "id", name = "id", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "姓名", name = "userName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "昵称", name = "nickName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "密码", name = "password", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "角色名称", name = "roleName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "角色id", name = "roleId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门名称", name = "departmentName", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门id", name = "departmentId", required = true, dataType = "string", paramType = "query"),
            @ApiImplicitParam(value = "部门code", name = "departmentCode", required = true, dataType = "string", paramType = "query")
    })
    public ResponseEntity modify(
            @RequestParam("id") Long id,
            @RequestParam("userName") String userName,
            @RequestParam("nickName") String nickName,
            @RequestParam("password") String password,
            @RequestParam("roleName") String roleName,
            @RequestParam("roleId") Long roleId,
            @RequestParam("departmentName") String departmentName,
            @RequestParam("departmentId") Long departmentId,
            @RequestParam("departmentCode") String departmentCode
    ) {
        Manager manager = new Manager();
        manager.setId(id);
        manager.setUserName(userName);
        manager.setNickName(nickName);
        manager.setPassword(password);
        manager.setRoleName(roleName);
        manager.setRoleId(roleId);
        manager.setDepartmentName(departmentName);
        manager.setDepartmentId(departmentId);
        manager.setDepartmentCode(departmentCode);
        return new JsonConvert<ResponseEntity>().jsonDecode(managerOperateConsumer.modify(manager), ResponseEntity.class);
    }

    @ApiOperation("删除人员")
    @PostMapping("/removeById")
    @ApiImplicitParam(value = "id", name = "id", required = true, dataType = "string", paramType = "query")
    public ResponseEntity removeById(
            @RequestParam("id") Long id
    ) {
        return new JsonConvert<ResponseEntity>().jsonDecode(managerOperateConsumer.removeById(id), ResponseEntity.class);
    }
}
